package com.exsun.ex1077.network.entity

import com.amap.api.maps.model.LatLng
import com.exsun.ex1077.R
import com.zhangping.amap.cluster.ClusterItem
import java.io.Serializable

//{
//    "pte": "2022-08-02 11:41:57",
//    "vehicleNo": "鄂AEH670",
//    "sts": [
//    2,
//    21,
//    39
//    ],
//    "lng": 114.78944,
//    "spd": 0,
//    "companyName": "华源新洲华光分公司",
//    "location": "湖北省,武汉市,新洲区,距离大袁倚马701米",
//    "isOnline": 0,
//    "videoOnline": 1,
//    "dvo": "020220401488",
//    "lat": 30.824466,
//      "objType": 0,
//      "objIcon": "truck_active",
//      "onlineStatusText": "熄火",
//}

data class MapVehicle(
    val companyName: String = "",
    val dvo: String = "",
    var isOnline: Int = 0,
    var videoOnline: Int = 0,
    var hasChannel: Int = 0,
    var lat: Double = 0.0,
    var lng: Double = 0.0,
    var location: String = "",
    var gdt: String = "",
    var spd: Int = 0,
    var dre: Int = 0,
    val sts: List<Int>? = null,
    val vehicleNo: String = "",
    val objType: Int = 0, //0车辆，1船舶，2人员，3物品，4动物，5其他
    val objIcon: String = "",
    val onlineStatus: Int = 0,
    val onlineStatusText: String = "",
    var checked: Boolean = false,
    val equipmentId: String = "",
    val channels: String = ""
): ClusterItem, Serializable {
    override fun id() = dvo

    override fun getPosition() = LatLng(lat, lng)

    override fun getType() = 0

    override fun <T : Any> getModel(): T  = this as T

    fun isOnlineA() = isOnline == 1

    fun isHasChannel() = hasChannel > 0

    fun onlineText() = onlineStatusText

    fun deviceNoText() = "设备号：$dvo"

    fun deviceNumberText() = "设备号码：$dvo"

    fun companyNameText() = "所属公司：$companyName"

    fun lastSpeedText() = "最后速度：${spd}km/h"

    fun lastLocationTime() = "最后定位时间：$gdt"

    fun lastLocationAddress() = "最后定位位置：$location"

    fun onlineStatusBgDrawableId() = when(onlineStatus){
        0,6 -> R.drawable.map_cluster_bg_run
        1 -> R.drawable.map_cluster_bg_stop
        2 -> R.drawable.map_cluster_bg_flameout
        3 -> R.drawable.map_cluster_bg_location_fail
        else -> R.drawable.map_cluster_bg_offline
    }

    fun updateData(newModel: MapVehicleGps){
        lat = newModel.lat
        lng = newModel.lng
        gdt = newModel.gdt
        dre = newModel.dre
        location = newModel.location
        isOnline = newModel.isOnline
        hasChannel = newModel.hasChannel
        videoOnline = newModel.videoOnline
    }
}